package za.org.jcicada.datastore.impl;

import java.net.URISyntaxException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import za.org.jcicada.cfgmngr.IConfigurationClient;
import za.org.jcicada.cfgmngr.IConfigurationServer;
import za.org.jcicada.cfgmngr.ISystemObserver;
import za.org.jcicada.cfgmngr.SystemSetType;
import za.org.jcicada.genss.ServiceURN;
import za.org.jcicada.genss.SystemURN;
import za.org.jcicada.genss.messages.Result;
import za.org.jcicada.genss.sensor.SensorURN;

public class SystemObserver implements ISystemObserver {

    /** Class logger */
    private static final Log logger = LogFactory.getLog(SystemObserver.class);
    
    private IConfigurationServer configurationServer;
    private IConfigurationClient configurationClient;
    
    public SystemObserver(IConfigurationServer configurationServer, IConfigurationClient configurationClient) {
    	this.configurationServer = configurationServer;
    	this.configurationClient = configurationClient;
    }
    
	public void informDisconnect() {
		// do nothing
	}

	public void informSystemEvent(SystemURN systemURN, SystemSetType type, Event event) {
		if (event == ISystemObserver.Event.REGISTERED) {
			try {
				configurationServer.requestLocateService(configurationClient, new ServiceURN(systemURN, SensorURN.URN_SERVICE_SENSORS), "tcp");
			} catch (URISyntaxException e) {
				logger.error(e);
			}
		}
	}

	public void replyAttach(Result result) {
	}

	public void replyDetach(Result result) {
	}

}
